package com.test.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.test.common.Page;
import com.test.common.R;
import com.test.common.SystemConstant;
import com.test.entity.SysRole;
import com.test.service.SysRoleService;



@RestController
@RequestMapping("/sys/role")
public class SysRoleController extends AbstractController {

	@Resource
	private SysRoleService sysRoleService;

	/**
	 * 获取角色列表
	 * @param params
	 * @return
	 */
	@RequestMapping("/list")
	public Page<SysRole> listRole(@RequestBody Map<String, Object> params) {
	/*	if (getUserId() != SystemConstant.SUPER_ADMIN) {
			params.put("userIdCreate", getUserId());
		}*/
		return sysRoleService.listRole(params);
	}
	
	/**
	 * 用户角色
	 * @return
	 */
	@RequestMapping("/select")
	public R listRole() {
		return sysRoleService.listRole();
	}
	
	/**
	 * 新增角色信息
	 * @param role
	 * @return
	 */
	@RequestMapping("/save")
	public R saveRole(@RequestBody SysRole role) {
		return sysRoleService.saveRole(role);
	}
	
	/**
	 * 通过id获取角色信息
	 * @param id
	 * @return
	 */
	@RequestMapping("/info")
	public R getRoleById(@RequestBody Long id) {
		
		return sysRoleService.getRoleById(id);
	}
	
	/**
	 * 更新角色信息
	 * @param role
	 * @return
	 */
	@RequestMapping("/update")
	public R updateRoleById(@RequestBody SysRole role) {
		return sysRoleService.updateRole(role);
	}
	
	/**
	 * 批量删除
	 * @param id
	 * @return
	 */
	@RequestMapping("/remove")
	public R deleteRole(@RequestBody Long[] id) {
		return sysRoleService.batchRemove(id);
	}
	
	/**
	 * 分配权限
	 * @param role
	 * @return
	 */
	@RequestMapping("/authorize")
	public R updateRoleAuthorization(@RequestBody SysRole role) {
		return sysRoleService.updateRoleAuthorization(role);
	}
}
